////////////////////////////////////////////////////////////////////////////////
//      
//      Kingsoft File for shp routines file
//      
//      File      : she_def.h
//      Comment   : simple html parser define file class
//					
//      Create at : 2012-12-06 19:09:56
//      Create by : chenguicheng
//      
////////////////////////////////////////////////////////////////////////////////

#pragma once
#include "common/shp_misc.h"


interface IShpParse
{
	virtual void set_attribute( LPTSTR p_key, LPTSTR p_value ) = 0;
};


enum{
	item_state_normal = 0,
	item_state_hover = 1,
	item_state_down = 2,
	item_state_disable = 3
};

//////////////////////////////////////////////////////////////////////////
//
//	shp_item Macro
//	add one tag attribute macro
//
#define BEGIN_KEY_MAP() \
	virtual void set_attribute( LPTSTR p_key, LPTSTR p_value )\
	{

#define ADD_STR_KEY(lp_key_text, member ) \
	if( _tcsicmp(p_key, lp_key_text ) == 0 )\
	{\
		member = shpstr(p_value);\
	}

#define ADD_FONT_KEY(lp_key_text, member ) \
	if( _tcsicmp(p_key, lp_key_text ) == 0 )\
	{\
		member = LOWORD(HexStringToDW(p_value));\
	}

#define ADD_HEX_KEY(lp_key_text, member ) \
	if( _tcsicmp(p_key, lp_key_text ) == 0 )\
	{\
		member = HexStringToDW(p_value);\
	}

#define ADD_POS_KEY(lp_key_text, n1, n2, n3, n4) \
	if( _tcsicmp(p_key, lp_key_text ) == 0 )\
	{\
		pos_to_int(shpstr(p_value), n1, n2, n3, n4 );\
	}

#define ADD_INT_KEY( lp_key_text, member ) \
	if( _tcsicmp(p_key, lp_key_text ) == 0 )\
	{\
		member =  _ttoi(p_value);\
	}

#define ADD_BOOL_KEY( lp_key_text, member ) \
	if( _tcsicmp(p_key, lp_key_text ) == 0 )\
	{\
		member = (BOOL)_ttoi(p_value);\
	}

#define ADD_ULONG_KEY( lp_key_text, member ) \
	if( _tcsicmp(p_key, lp_key_text ) == 0 )\
	{\
		member =  _ttol(p_value);\
	}

#define ADD_HBITMAP_KEY( lp_key_text, member ) \
	if( _tcsicmp(p_key, lp_key_text ) == 0 )\
	{\
		member =  (HBITMAP)_ttoi(p_value);\
	}

#define ADD_CLR_KEY( lp_key_text, member ) \
	if( _tcsicmp(p_key, lp_key_text ) == 0 )\
	{\
		member = _ttoclr(p_value);\
	}

#define BASE_CLASS_PROCESS(baseclass) \
	baseclass::set_attribute( p_key, p_value );

#define END_KEY_MAP()	};


//////////////////////////////////////////////////////////////////////////
//
//	shp_shpparser Macro
//  add all tag class macro
//
#define BEGIN_BASE_CLASS_MAP() \
	shp_dom_item* _get_base_class_ptr( LPTSTR tsz_type )\
	{\
		shp_dom_item * p_item = NULL;


#define ADD_TYPE_CLASS( lp_type_key, class_name ) \
	if( _tcsicmp(tsz_type, lp_type_key ) == 0 )\
	{\
		p_item = ( shp_dom_item* )new shp_tree_item< class_name >;\
	}

#define END_BASE_CLASS_MAP() \
		return p_item; \
	}


//////////////////////////////////////////////////////////////////////////
//
//	shp_shpparser Macro
//  get/set attribute macro
//

//bool set_item_left( DWORD dw_id, int n_left )
//{
//	shp_dom_item* p_item = get_item_by_id( dw_id );
//	assert( p_item );
//	if ( p_item )
//	{
//		p_item->set_i_left( n_left );
//		_re_init( p_item );
//		return true;
//	}
//	return false;
//}

//bool get_item_left( DWORD dw_id, int& n_out )
//{
//	shp_dom_item* p_item = get_item_by_id( dw_id );
//	if ( p_item )
//	{
//		n_out = p_item->get_i_left();
//		return true;
//	}
//	return false;
//}

#define  GET_BASE_ATTRIBUTE( fun_out, fun_item, classOut )	\
bool fun_out( DWORD dw_id, classOut& outRet )				\
{														\
	shp_dom_item* p_item = get_item_by_id( dw_id );		\
	if ( p_item )										\
	{													\
		outRet = p_item->fun_item();					\
		return true;									\
	}													\
	return false;										\
}

#define SET_BASE_ATTRIBUTE( fun_out, fun_item, classIn ) \
bool fun_out( DWORD dw_id, classIn& inRet )				\
{														\
	shp_dom_item* p_item = get_item_by_id( dw_id );		\
	if ( p_item )										\
	{													\
		p_item->fun_item( inRet );						\
		return true;									\
	}													\
	return false;										\
}